/*
 * @Author: C.
 * @Date: 2021-12-21 19:15:57
 * @LastEditTime: 2021-12-23 15:38:05
 * @Description: file content
 */
/**
 * 响应拦截
 * @param {Object} http 
 */
module.exports = (vm) => {
    uni.$u.http.interceptors.response.use((response) => { /* 对响应成功做点什么 可使用async await 做异步操作*/
        const {Code,Data,Msg,MsgType} = response.data
        responseFilter(MsgType,Msg)
    if(Code===401){
      uni.reLaunch({
        url: "/pages/Login/index"
      });
      return Promise.reject(Msg)
    }else if(Code===200){
      return Data
    }else{
      return Promise.reject(Msg)
    }
    }, (response) => { /*  对响应错误做点什么 （statusCode !== 200）*/
        return Promise.reject(response)
    })
}

function responseFilter(type,msg){
  if(['success','warning','error'].includes(type)){
    uni.showToast({
  title: msg,
  icon: type,
  duration: 2000,
})
  }
}